package com.panopset.gui;

import java.math.BigDecimal;

import com.panopset.Strings;

public class ValidatingBigDecimal extends ValidatingField<BigDecimal> {

	/**
	 * @param name
	 *            Name of field, used in validation messages.
	 */
	public ValidatingBigDecimal(final String name) {
		super(name);
	}

	@Override
	public BigDecimal getValue() throws Exception {
		try {
			return new BigDecimal(getTf().getText());
		} catch (NumberFormatException ex) {
			return BigDecimal.ZERO;
		}
	}

	@Override
	public boolean validate(final String s) {
		if (!Strings.isPopulated(s)) {
			return false;
		}
		try {
			new BigDecimal(s);
			return true;
		} catch (NumberFormatException ex) {
			return false;
		}
	}

	@Override
	public void save() {
		// TODO Auto-generated method stub

	}

}
